package com.tipcp.equip.collect.controller;

import com.tipcp.equip.collect.domain.EquipEsModel;
import com.tipcp.equip.collect.service.EquipService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

@RestController
@RequestMapping("/equip")
@Tag(name = "设备ES-API")
public class EquipController {

    @Autowired
    private EquipService service;

    @PostMapping
    @Operation(summary = "新增")
    public EquipEsModel save(@RequestBody EquipEsModel equip) {
        return service.save(equip);
    }

    @GetMapping("/{id}")
    @Operation(summary = "根据ID查询")
    public Optional<EquipEsModel> get(@PathVariable String id) {
        return service.findById(id);
    }

    @GetMapping
    @Operation(summary = "获取列表")
    public Iterable<EquipEsModel> getAll() {
        return service.findAll();
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除")
    public void delete(@PathVariable String id) {
        service.deleteById(id);
    }

    @PostMapping("/collect")
    @Operation(summary = "采集")
    public void collect() {
        service.collect();
    }
}

